﻿DROP TRIGGER IF EXISTS  `pk_buyershow_log`; 
CREATE  TRIGGER `pk_buyershow_log` AFTER INSERT ON `open_buyer_show`
  FOR EACH ROW BEGIN

DECLARE pkf varchar(50) DEFAULT "";

SELECT pk_from INTO pkf FROM open_pk_log WHERE pk_from="buyer_show";

if pkf <> "buyer_show" then

   INSERT INTO open_pk_log SET pk_from = 'buyer_show', pk_id = NEW.id;

ELSE

    update open_pk_log SET pk_id = NEW.id WHERE pk_from = 'buyer_show';

end if;

END;